﻿// CSetting.cpp: 实现文件
//

#include "pch.h"
#include "MFCDrawingBoard.h"
#include "CSetting.h"
#include "afxdialogex.h"


#define ID_HOTKEY_Y 1001
#define ID_RED_LINE 1002
#define ID_BLACK_LINE 1003
#define ID_RUBBER 1004
#define ID_RECT 1005
#define ID_CIRCLE 1006
#define ID_ELLPISE 1007
#define ID_DRAG 1008

// CSetting 对话框

IMPLEMENT_DYNAMIC(CSetting, CDialogEx)

CSetting::CSetting(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG1, pParent)
{

}

CSetting::~CSetting()
{
}

void CSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_RADIO_RED, m_radioRed);
	DDX_Control(pDX, IDC_RADIO_BLACK, m_radioBlack);
	DDX_Control(pDX, IDC_RADIO_Rubber, m_radioRubber);
	DDX_Control(pDX, IDC_RADIO_RECT, m_radioRect);
	DDX_Control(pDX, IDC_RADIO_CIRCLE, m_radioCircle);
	DDX_Control(pDX, IDC_RADIO_MOVE, m_radioDrag);
	DDX_Control(pDX, IDC_RADIO_ELLIPSE, m_radioEllipse);
}


BEGIN_MESSAGE_MAP(CSetting, CDialogEx)
	ON_BN_CLICKED(IDOK, &CSetting::OnBnClickedOk)
	ON_WM_HOTKEY()
	ON_BN_CLICKED(IDC_RADIO_RED, &CSetting::OnBnClickedRadioRed)
	ON_BN_CLICKED(IDC_RADIO_BLACK, &CSetting::OnBnClickedRadioBlack)
	ON_BN_CLICKED(IDC_RADIO_Rubber, &CSetting::OnBnClickedRadioRubber)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR, &CSetting::OnBnClickedButtonClear)
	ON_BN_CLICKED(IDC_RADIO_RECT, &CSetting::OnBnClickedRadioRect)
	ON_BN_CLICKED(IDC_RADIO_CIRCLE, &CSetting::OnBnClickedRadioCircle)
	ON_BN_CLICKED(IDC_RADIO_MOVE, &CSetting::OnBnClickedRadioDrag)
	ON_BN_CLICKED(IDC_RADIO_ELLIPSE, &CSetting::OnBnClickedRadioEllipse)
END_MESSAGE_MAP()


// CSetting 消息处理程序


BOOL CSetting::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	//RegisterHotKey(GetSafeHwnd(), ID_HOTKEY_Y, MOD_ALT | MOD_CONTROL, 'Y'); //注册的热键为ctrl+alt+Y 
	RegisterHotKey(GetSafeHwnd(), ID_RED_LINE, MOD_CONTROL, '1'); 
	RegisterHotKey(GetSafeHwnd(), ID_BLACK_LINE, MOD_CONTROL, '2'); 
	RegisterHotKey(GetSafeHwnd(), ID_RECT, MOD_CONTROL, '3'); 
	RegisterHotKey(GetSafeHwnd(), ID_CIRCLE, MOD_CONTROL, '4'); 
	RegisterHotKey(GetSafeHwnd(), ID_ELLPISE, MOD_CONTROL, '5'); 
	RegisterHotKey(GetSafeHwnd(), ID_RUBBER, MOD_CONTROL, '6'); 
	RegisterHotKey(GetSafeHwnd(), ID_DRAG, MOD_CONTROL, '7'); 

	SetAllRadioCheck(0);
	m_radioRed.SetCheck(1);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CSetting::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnOK();
}


void CSetting::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nHotKeyId == ID_HOTKEY_Y) {
		AfxMessageBox(_T("HOTKEY_Y"), MB_OK, 2);//这里的处理代码是弹出一个窗口
	}

	switch (nHotKeyId)
	{
	case ID_RED_LINE:
		OnBnClickedRadioRed();
		break;

	case ID_BLACK_LINE:
		OnBnClickedRadioBlack();
		break;

	case ID_RECT:
		OnBnClickedRadioRect();
		break;

	case ID_CIRCLE:
		OnBnClickedRadioCircle();
		break;

	case ID_ELLPISE:
		OnBnClickedRadioEllipse();
		break;

	case ID_RUBBER:
		OnBnClickedRadioRubber();
		break;

	case ID_DRAG:
		OnBnClickedRadioDrag();
		break;

	default:
		break;
	}

	CDialogEx::OnHotKey(nHotKeyId, nKey1, nKey2);
}


void CSetting::OnBnClickedRadioRed()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioRed.SetCheck(1);
}


void CSetting::OnBnClickedRadioBlack()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioBlack.SetCheck(1);
}


void CSetting::OnBnClickedRadioRubber()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioRubber.SetCheck(1);
}


void CSetting::SetAllRadioCheck(int n)
{
	// TODO: 在此处添加实现代码.
	m_radioRed.SetCheck(n);
	m_radioBlack.SetCheck(n);
	m_radioRubber.SetCheck(n);
	m_radioRect.SetCheck(n);
	m_radioCircle.SetCheck(n);
	m_radioDrag.SetCheck(n);
	m_radioEllipse.SetCheck(n);
}


void CSetting::OnBnClickedButtonClear()
{
	// TODO: 在此添加控件通知处理程序代码
	if (m_fnCallback != nullptr)
	{
		m_fnCallback();
	}
}


void CSetting::OnBnClickedRadioRect()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioRect.SetCheck(1);
}


void CSetting::OnBnClickedRadioCircle()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioCircle.SetCheck(1);
}


void CSetting::OnBnClickedRadioDrag()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioDrag.SetCheck(1);
}


void CSetting::OnBnClickedRadioEllipse()
{
	// TODO: 在此添加控件通知处理程序代码
	SetAllRadioCheck(0);
	m_radioEllipse.SetCheck(1);
}
